package com.chunuo.blogs.controller;

import com.chunuo.blogs.entity.Comment;
import com.chunuo.blogs.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评论
 *
 * @author liujiamiao
 * @email 2544296058@qq.com
 * @date 2020-05-27 12:05
 */
@RestController
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 评论
     * @param comment
     * @return
     */
    @PostMapping("/comment")
    public List<Comment> save(@RequestBody Comment comment){
        System.out.println("comment ========= " + comment);
        commentService.save(comment);
        return commentService.findAll(comment.getBlogsId());
    }

    /**
     * 删除评论
     * @param id
     * @return
     */
    @DeleteMapping("/comment/{id}")
    public Integer delete(@PathVariable("id") Integer id){
        commentService.delete(id);
        return 1;
    }

}
